    <div class="row">
        <div class="col-xs-12">
        <!-- /.box -->
            <div class="box">
                <div class="box-header">
                            <div id='SearchForm'>
                                <div class="row " style="line-height:33px; display: flex;padding-left: 20px;">
                                    <div class="form-group">
                                        <a href="<?= base_url()?>index.php/admin/<?= $module?>/create" class="btn btn-primary bg-pink btn-big">新建商品</a>
                                    </div>

                                    <div class="form-group">
                                        <select name="status" style='width:120px;' class='form-control'>
                                            <option value=""><?=$is_start_label ?></option>
                                            <?php
                                            foreach ($is_start_opts as $key => $opts) {
                                            ?>
                                                <option value="<?=$opts['opts_key'] ?>" <?php if(isset($search['status']) && $search['status'] == $opts['opts_key']) echo 'selected';?>><?=$opts['opts_val'] ?></option>
                                            <?php
                                            }
                                            ?>
                                        </select>
                                    </div>&nbsp;&nbsp;
                                    <?php if('yes' == $is_admin){?>
                                        <div class="form-group">
                                            <select name="brand_id" style='width:120px;' class='form-control'>
                                                <option value="">请选择品牌</option>
                                                <?php
                                                foreach ($brand_opts as $key => $opts) {
                                                ?>
                                                    <option value="<?=$opts['id'] ?>" <?php if(isset($search['brand_id']) && $search['brand_id'] == $opts['id']) echo 'selected';?>><?=$opts['name'] ?></option>
                                                <?php
                                                }
                                                ?>
                                            </select>
                                        </div>&nbsp;&nbsp;
                                    <?php }?>
                                    <div class="form-group">
                                        <select name="category_first" style='width:120px;' class="form-control" seld="<?=$search['category_first'] ?>">
                                            <option value="">一级分类</option>
                                        </select>
                                    </div>&nbsp;&nbsp;
                                    <div class="form-group">
                                        <select name="category_parent" style='width:120px;' class="form-control" seld="<?=$search['category_parent'] ?>">
                                            <option value="">二级分类</option>
                                        </select>
                                    </div>&nbsp;&nbsp;
                                    <div class="form-group">
                                        <select name="category_id" style='width:120px;' class="form-control" seld="<?=$search['category_id'] ?>">
                                            <option value="">三级分类</option>
                                        </select>
                                    </div>

                                    <div class="col-xs-4">
                                        <input type="text" class="form-control" name="name" style='width:150px;'
                                                placeholder="请输入商品名称。"
                                            value="<?php echo (isset($search['name'])?$search['name']:'') ?>">
                                    </div>
                                    <div class="col-xs-4">
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="button" id='searchBtn' class='btn btn-default' value='搜索'>
                                        &nbsp;
                                    </div>
                                </div>
                            </div>

                </div>
                <div class="box-body">
                    <table class="table table-bordered text-center" id='ListTab'>
                        <thead>
                        <tr>
                            <th><input type="checkbox" class="market-check-all" id='allselected'></th>
                            <th nowrap>商品主图</th>
                            <th nowrap>商品编号</th>
                            <th nowrap>商品标题</th>
                            <?php if('yes' == $is_admin){?>
                                <th nowrap>品牌</th>
                            <?php }?>
                            <th nowrap>商品分类</th>
                            <th nowrap>状态</th>
                            <th nowrap>更新时间</th>
                            <th nowrap>操作</th>
                        </tr></thead>
                        <tbody>
                            <?php
                            foreach ($goodsList as $key=>$goods) {
                            ?>
                                <tr style='text-align: center;'>
                                    <td><input type="checkbox" class="market-check" value="<?= $goods['id']?>"></td>
                                    <td>
                                        <?php if(!empty($goods['imageurl'])){?>
                                            <img id="picurl" src="<?= $goods['imageurl']?>" width="60" height="60">
                                        <?php }?>
                                    </td>
                                    <td><?= $goods['code']?></td>
                                    <td><?= $goods['name']?></td>
                                    <?php if('yes' == $is_admin){?>
                                        <th><?= $goods['brand_name']?></th>
                                    <?php }?>
                                    <td>
                                        <?= $goods['category_first_name']?>
                                        -
                                        <?= $goods['category_parent_name']?>
                                        -
                                        <?= $goods['category_id_name']?>
                                    </td>
                                    <td>
                                        <?php if(1 == $goods['status']){?>
                                            <span class="label label-success">在售</span>
                                        <?php }else{?>
                                            <span class="label label-gray">已下架</span>
                                        <?php }?>
                                    </td>
                                    <td><?= $goods['update_time']?></td>
                                    <td nowrap>
                                        <a class="btn btn-default btn-xs btn-flat margin" href='<?= base_url()?>index.php/admin/<?= $module?>/edit/<?= $goods['id']?>' tag='edit_link'>编辑</a>
                                        <a class="btn btn-default btn-xs btn-flat margin" href='javascript:;' tag='enable_link'
                                                goods_id="<?= $goods['id']?>" status="<?=$goods['status']?>" >
                                            <?php if(1 == $goods['status']){?>
                                                下架
                                            <?php }else{?>
                                                上架
                                            <?php }?>
                                        </a>
                                        <?php if('yes' == $is_admin){?>
                                            <a class="btn btn-default btn-xs btn-flat margin" href='javascript:;' byid="<?= $goods['id']?>" tag='delete_link'>删除</a>
                                        <?php }?>
                                    </td>
                                </tr>
                            <?php
                            }
                            ?>
                            <tr>
                                <td colspan="9" style='text-align: right;display: none;'>
                                    <span style='word-spacing:8px; letter-spacing: 10px;' id='paginate'>
                                        <?=$paginate?>
                                    </span>
                                </td>
                            </tr>
                    </tbody></table>
                </div>
                <!-- /.box-body -->
                <div class="box-footer clearfix">

                    <button type="button" class="btn btn-default margin_left5" updatestatus='1'>批量上架</button>
                    <button type="button" class="btn btn-default margin_left5" updatestatus='0'>批量下架</button>

                    <ul class="pagination pagination-sm no-margin pull-right" id='paginateul'></ul>
                    <span class='no-margin pull-right' style='padding-right:40px;'><?=$pagetitle?></span>
                </div>
            </div>
        </div>
    <!-- /.col -->
    </div>
<!-- /.row -->
<script>
$(function(){
    var is_submit = 1;
    var cur_page = "<?=$cur_page?>";
    $('a[tag=delete_link]').on('click',function(){
        if(confirm('确定要删除吗？')){
            $.get('<?=base_url()?>index.php/admin/<?= $module?>/destroy/'+$(this).attr('byid'),function(rest){
                if($('#ListTab > tbody > tr').length == 2 && cur_page > 1){
                    $('#searchBtn').attr('cur_page',(cur_page-1));
                    $('#searchBtn').click();
                }else{
                    $('#searchBtn').attr('cur_page',cur_page);
                    $('#searchBtn').click();
                }
            });
        }
        return false;
    });
    $('#createBtn').on('click',function (){
        location.href = 'create';
    });
    $('#searchBtn').on('click',function(){
        var param = {};
        $('#SearchForm input[name],select[name]').each(function(){
            if($(this).val() != ''){
                param[$(this).attr('name')] = $(this).val();
            }
        });
        if($(this).attr('cur_page') > 0){
            param['cur_page'] = $(this).attr('cur_page');
        }else{
            param['cur_page'] = 1;
        }
        $(this).attr('cur_page',0);
        searchList(param);
    });
    $('#SearchForm input[name]').on({
        'keypress':function (event){
            var e = window.event||event;
            if(13 == e.keyCode){
                $('#searchBtn').click();
            }
        }
    });
    //将ci的分页放到新的版本中去
    if($('#paginate a').length > 0){
        var paginateul = '';var link_href = '';var link_val = '';
        $('#paginate a,strong').each(function (){
            link_val = $(this).html();
            link_href = $(this).attr('href');
            if(link_href != undefined){
                if('Last ›' == link_val){
                    link_val = '>>';
                }else if('‹ First' == link_val){
                    link_val = '<<';
                }
                paginateul += '<li><a href="'+link_href+'">'+link_val+'</a></li>';
            }else{
                paginateul += '<li><a href="#" onclick="return false;" style="color:#428bca;"><b>'+link_val+'</b></a></li>';
            }
        });
        $('#paginateul').html(paginateul);
        //绑定分页事件
        $('#paginateul').on('click','a[href]',function(){
            var url = $(this).attr('href');
            if('#' == url) return false;
            var urlarr = url.split('=');
            var cur_page = urlarr[urlarr.length-1];
            if(isNaN(cur_page)) cur_page = 1;
            var param = {};
            $('#SearchForm input[name],select[name]').each(function(){
                if($(this).val() != ''){
                    param[$(this).attr('name')] = $(this).val();
                }
            });
            param['cur_page'] = parseInt(cur_page);
            searchList(param);
            return false;
        });
    }
    //全选
    $('#allselected').on('click',function(){
        $('#ListTab tbody input[type=checkbox].market-check').prop('checked',$(this).prop('checked'));
    });
    //批量上下架
    $('button[updatestatus]').on('click',function(){
        //$(this).attr('updatestatus')
        if(0 == $('#ListTab tbody input[type=checkbox]:checked').length){
            alert('请选择商品。');
            return false;
        }
        var updatestatus = $(this).attr('updatestatus');
        if(1 == updatestatus){
            var title = '上架';
        }else{
            var title = '下架';
        }
        if(confirm('您确定要'+title+'这些商品吗？')){
            var goods_id = '';
            $('#ListTab tbody input[type=checkbox]:checked').each(function(){
                if(goods_id == ''){
                    goods_id = $(this).val();
                }else{
                    goods_id += ','+$(this).val();
                }
            });
            var param = {};
            param['updatestatus'] = updatestatus;
            param['goods_id'] = goods_id;
            $.post('<?=base_url()?>index.php/admin/goods/updateStatus',param,function(rest){
                $('#searchBtn').attr('cur_page',cur_page);
                $('#searchBtn').click();
            });
        }
    });
    //上下架
    $('a[tag=enable_link').on('click',function(){
        var param = {};
        param['status'] = $(this).attr('status');
        $.get('<?=base_url()?>index.php/admin/goods/enable/'+$(this).attr('goods_id'),param,function(rest){
            $('#searchBtn').attr('cur_page',cur_page);
            $('#searchBtn').click();
        });
    });

//三级联动
//绑定一级分类事件
$('#SearchForm select[name=category_first]').on('change',function(){
    var brand_id = 0;
    if($('#SearchForm select[name=brand_id]').length > 0){
        brand_id = $('#SearchForm select[name=brand_id]').val();
    }
    $('#SearchForm select[name=category_parent]').get(0).length = 1;
    if($(this).val() > 0){
        parent_id = $(this).val();
    }else{
        return false;
    }
    $.post('<?=base_url()?>index.php/admin/category/getCategoryByParent',{'ajax':1,'parent_id':parent_id,'brand_id':brand_id},function(rest){
        if(rest == '') return false;
        var restobj = eval('('+ rest +')')?eval('('+ rest +')'):JSON.parse(rest);
        $.each(restobj.data,function (key,opts){
            $('#SearchForm select[name=category_parent]').append('<option value="'+opts.id+'">'+opts.name+'</option>')
        });
        if($('#SearchForm select[name=category_parent]').attr('seld') > 0){
            $('#SearchForm select[name=category_parent]').val($('#SearchForm select[name=category_parent]').attr('seld'));
            $('#SearchForm select[name=category_parent]').change();
            $('#SearchForm select[name=category_parent]').attr('seld',0);
        }
    });
});
//绑定二级分类事件
$('#SearchForm select[name=category_parent]').on('change',function(){
    var brand_id = 0;
    if($('#SearchForm select[name=brand_id]').length > 0){
        brand_id = $('#SearchForm select[name=brand_id]').val();
    }
    $('#SearchForm select[name=category_id]').get(0).length = 1;
    if($(this).val() > 0){
        parent_id = $(this).val();
    }else{
        return false;
    }
    $.post('<?=base_url()?>index.php/admin/category/getCategoryByParent',{'ajax':1,'parent_id':parent_id,'brand_id':brand_id},function(rest){
        if(rest == '') return false;
        var restobj = eval('('+ rest +')')?eval('('+ rest +')'):JSON.parse(rest);
        $.each(restobj.data,function (key,opts){
            $('#SearchForm select[name=category_id]').append('<option value="'+opts.id+'">'+opts.name+'</option>')
        });
        if($('#SearchForm select[name=category_id]').attr('seld') > 0){
            $('#SearchForm select[name=category_id]').val($('#SearchForm select[name=category_id]').attr('seld'));
            $('#SearchForm select[name=category_id]').change();
            $('#SearchForm select[name=category_id]').attr('seld',0);
        }
    });
});

/**
 * 加载分类事件
 * @author Toby.tu 2017-03-06
 */
function loadCategoryOpts(brand_id=0){
    $.post('<?=base_url()?>index.php/admin/category/getCategoryByParent',{'ajax':1,'parent_id':0,'brand_id':brand_id},function(rest){
        $('#SearchForm select[name=category_first]').get(0).length = 1;
        if(rest == '') return false;
        var restobj = eval('('+ rest +')')?eval('('+ rest +')'):JSON.parse(rest);
        $.each(restobj.data,function (key,opts){
            $('#SearchForm select[name=category_first]').append('<option value="'+opts.id+'">'+opts.name+'</option>')
        });
        if($('#SearchForm select[name=category_first]').attr('seld') > 0){
            $('#SearchForm select[name=category_first]').val($('#SearchForm select[name=category_first]').attr('seld'));
            // $('#SearchForm select[name=category_first]').trigger('change');
            $('#SearchForm select[name=category_first]').change();
            $('#SearchForm select[name=category_first]').attr('seld',0);
        }
    });
}
if($('#SearchForm select[name=brand_id]').length > 0){
    $('#SearchForm select[name=brand_id]').on('change',function(){
        loadCategoryOpts($(this).val());
    });
    if($('#SearchForm select[name=brand_id]').val() > 0){
        $('#SearchForm select[name=brand_id]').change();
    }
}else{
    loadCategoryOpts();
}
});
</script>
